using System.Collections.Generic;
using Avalonia.Interactivity;
using DotManager.ViewModels.Pages;
using FluentAvalonia.UI.Controls;
using FluentAvalonia.UI.Windowing;

namespace DotManager.Views;

public partial class MainWindow : AppWindow
{
    private readonly Dictionary<string, PageModelBase> Stack = [];
    public MainWindow()
    {
        
        Stack.Add("Home", new HomeViewModel());
        Stack.Add("Setting", new SettingViewModel());
        Stack.Add("Help", new HelpViewModel());
        
        InitializeComponent();
        
        TitleBar.ExtendsContentIntoTitleBar = true;
        TitleBar.TitleBarHitTestType = TitleBarHitTestType.Complex;

        FrameView.IsNavigationStackEnabled = true;
        FrameView.NavigationPageFactory = new NavigationFactory();
        Navigate("Home");
    }

    private void BackClick(object? sender, RoutedEventArgs e)
    {
        FrameView.GoBack();
    }

    private void ItemInvoked(object? sender, NavigationViewItemInvokedEventArgs e)
    {
        if (e.InvokedItemContainer.Tag is not string s) return;
        Navigate(s);
    }
    
    public void Navigate(string page)
    {
        if (string.IsNullOrEmpty(page)) return;
        Navigate(Stack[page]);
    }

    private void Navigate(object context)
    {
        FrameView.NavigateFromObject(context);
    }
}